import request from "@/utils/request";

//测试后端服务器是否正常
export const getTest = () => {
  return request({
    method: "get",
    url: "heath/hello",
  });
};


//登录
export const getLogin = (info) => {
  //return request.post("user/login", info)
  return request({
    method: "post",
    url: "user/login",
    data: info,
  });
};

// 注册接口
export const register = (info) => {
  return request({
    method: "post",
    url: "user/register",
    data: info,
  });
};

//重置密码
export const resetAccount = (info) => {
  return request({
    method: "put",
    url: "user/reset",
    data: info
  });
};

//注销账户
export const deleteAccountAPI = (userId) => {
  return request({
    method: "delete",
    url: `user/delete/${userId}`,
  });
};

//上传图片
export const uploadImageApi = (formData) => {
  return request({
    method: "post",
    url: "file/image",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    timeout: 60000,
  });
};

// 管理员上传图片（服务专用）
export const adminUploadImageApi = (formData) => {
  return request({
    method: "post",
    url: "file/admin/image",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    timeout: 60000,
  });
};

// 管理员上传分类图片（分类专用）
export const adminUploadCategoryImageApi = (formData) => {
  return request({
    method: "post",
    url: "file/admin/category/image",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    timeout: 60000,
  });
};

// 分类管理相关API
// 获取分类列表
export const getCategories = () => {
  return request({
    method: "get",
    url: "admin/category/list",
  });
};

// 添加分类
export const addCategory = (categoryData) => {
  return request({
    method: "post",
    url: "admin/category/add",
    data: categoryData,
  });
};

// 更新分类
export const updateCategory = (categoryId, categoryData) => {
  return request({
    method: "put",
    url: `admin/category/update/${categoryId}`,
    data: categoryData,
  });
};

// 删除分类
export const deleteCategory = (categoryId) => {
  return request({
    method: "delete",
    url: `admin/category/delete/${categoryId}`,
  });
};

export const adminLogin = (formData) => {
  return request({
    method: "post",
    url: "user/admin/login",
    data: formData,
  });
};

// 获取轮播图
export const getSliderImages = () => {
  return request({
    method: "get",
    url: "slider/list",
  });
};

// 获取服务卡片
export const getServiceCards = () => {
  return request({
    method: "get",
    url: "index/services",
  });
};

// 获取合作伙伴
export const getCooperations = () => {
  return request({
    method: "get",
    url: "cooperation/list",
  });
};

// 获取用户评价
export const getUserReviews = () => {
  return request({
    method: "get",
    url: "review/list",
  });
};

export const findBigType = () => {
    return request({
        method: "get",
        url: "category/findBigType",
    });
}

export const findSmallType = () => {
    return request({
        method: "get",
        url: "category/findSmallType",
    });
}

export const findService = () => {
    return request({
        method: "get",
        url: "category/findService",
    });
}

// 获取所有评价列表
export const getAllEvaluations = (params) => {
  return request({
    method: "get",
    url: "evaluation/list/all",
    params: params
  });
};

// 提交评价
export const addEvaluation = (evaluationData) => {
  return request({
    method: "post",
    url: "evaluation/add",
    data: evaluationData
  })
};

// 检查订单是否已评价
export const checkOrderEvaluation = (orderId) => {
  return request({
    method: "get",
    url: `evaluation/check/${orderId}`
  });
};

// 获取省份列表
export const getProvinceList = () => {
  return request({
    url: '/region/province',
    method: 'get'
  })
}

// 获取子地区列表
export const getChildRegions = (parentId) => {
  return request({
    url: '/region/child',
    method: 'get',
    params: { parentId }
  })
}

// 获取最快上门时间
export const getFastestArrivalTime = (regionId) => {
  return request({
    url: '/region/fastest',
    method: 'get',
    params: { regionId }
  })
}



// 领取优惠券
export const claimCoupon = (couponId) => {
  return request({
    method: "post",
    url: "index/coupon/claim",
    params: { couponId }
  });
};


// 管理员相关API
// 添加服务
export const addServiceCard = (serviceData) => {
  return request({
    method: "post",
    url: "admin/service/add",
    data: serviceData,
  });
};





// 获取物品类型
export const getItemTypes = () => {
  return request({
    method: "get",
    url: "item/types",
  });
};

// 创建订单
export const createOrder = (orderData) => {
  return request({
    method: "post",
    url: "order/create",
    data: orderData
  });
};

// 获取订单详情
export const getOrderDetail = (orderId) => {
  return request({
    method: "get",
    url: `order/detail/${orderId}`,
  });
};

// 更新订单
export const updateOrder = (orderId, orderData) => {
  return request({
    method: "put",
    url: `order/update/${orderId}`,
    data: orderData
  });
};

// ===== 窗帘安装订单相关 API =====

// 创建窗帘安装订单
export const createCurtainOrder = (orderData) => {
  return request({
    method: "post",
    url: "curtain-order/create",
    data: orderData
  });
};

// 获取窗帘订单详情
export const getCurtainOrderDetail = (orderId) => {
  return request({
    method: "get",
    url: `curtain-order/detail/${orderId}`,
  });
};

// 更新窗帘订单
export const updateCurtainOrder = (orderId, orderData) => {
  return request({
    method: "put",
    url: `curtain-order/update/${orderId}`,
    data: orderData
  });
};



// 获取维修类型
export const getRepairTypes = () => {
  return request({
    method: "get",
    url: "repair/types",
  });
};





// 获取可用优惠券列表
export const getAvailableCoupons = () => {
  return request({
    method: "get",
    url: "index/coupons",
  });
};



// 一键领取所有优惠券
export const claimAllCoupons = () => {
  return request({
    method: "post",
    url: "index/coupon/claim-all",
  });
};

// 管理员相关API

// 更新服务
export const updateServiceCard = (serviceId, serviceData) => {
  return request({
    method: "put",
    url: `admin/service/update/${serviceId}`,
    data: serviceData,
  });
};

// 删除服务
export const deleteServiceCard = (serviceId) => {
  return request({
    method: "delete",
    url: `admin/service/delete/${serviceId}`,
  });
};





//发布首页评价
export const publishReview = (reviewData) => {
  return request({
    method: "post",
    url: "index/addEvaluation",
    data: reviewData
  });
};

//获取首页评价列表
export const getEvaluations = () => {
  return request({
    method: "get",
    url: "index/evaluations"
  });
};


export const getOrders = (userId) => {
  return request({
    method: "get",
    url: "order/list",
    params: { userId: userId }
  });
};



// 发布评价到首页展示（pushView方法）
export const pushView = (reviewData) => {
  return request({
    method: "post",
    url: "index/addEvaluation",
    data: reviewData
  });
};

// 获取首页的用户评价
export const getHomeUserEvaluations = () => {
  return request({
    method: "get",
    url: "index/getIndexEvaluation",
  });
};


//删除订单
export const deleteOrder=(orderId)=>{
  return request({
    method:"post",
    url:"order/delete",
    params: { orderId: orderId }
  })
}
